﻿namespace com.stifel.BranchMgmt.WebParts.BranchView
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using com.stifel.BranchMgmtDao;

    using Microsoft.SharePoint;

    public partial class BranchViewUserControl
    {
        #region Methods

        int getBranchId( Guid ItemGuid )
        {
            StifelBranchInfoDao dao = new StifelBranchInfoDao( SPContext.Current.Web.Url );
            StifelBranchInfo value = dao.Get( ItemGuid );
            if ( value.Id.HasValue )
            {
                return ( value.Id.Value );
            }
            else
            {
                return ( 0 );
            }
        }

        void navigateToSelectedView( Button button )
        {
            string arg = button.CommandArgument;
            int index = -1;

            for ( int i = 0; i < uiView.Views.Count; i++ )
            {
                View view = uiView.Views[ i ];
                if ( view.ID.Equals( arg, StringComparison.OrdinalIgnoreCase ) )
                {
                    index = i;
                    break;
                }
            }
            uiView.ActiveViewIndex = index >= 0 ? index : uiView.Views.Count - 1;
            foreach ( Control c in uiNavigation.Controls )
            {
                Button b = c as Button;
                if ( b != null )
                {
                    b.Attributes.Remove( Attribute.Current );
                }
            }
            button.Attributes.Add( Attribute.Current, true.ToString( ) );
        }

        void setDefaultView( )
        {
            Button button = uiNavigation.FindControl( "uiBtnBasics" ) as Button;
            navigateToSelectedView( button );
        }

        #endregion Methods

        #region Nested Types

        class Attribute
        {
            #region Fields

            public const string Current = "current";

            #endregion Fields
        }

        #endregion Nested Types
    }
}